from src.backend.beanfactory import BeanFactory

def topic(type,level):
    _where=''
    _value=[]
    if type>1:
        _where+=" and category=?"
        _value.append(type)
    if level>1:
        _where+=" and level=?"
        _value.append(level)
    sql = """SELECT   
        t.content 资源内容,  
        (SELECT name FROM type WHERE id = t.category) AS 类型,  
        (SELECT name FROM topic_level WHERE id = t.level) AS 难度等级,  
        t.answer 答案
    FROM   
        topic t  
    WHERE
        1=1 """+_where
    results = BeanFactory.getCursor().query(sql,tuple(_value))
    return results
